package com.naiterui.ehp.bs.doctor.dao.mongo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.ehp.bs.doctor.prodocl.MPatientDocument;

/**
 * <患者档案持久层>
 *
 * @version 2015年7月20日 上午11:35:22 by Amber
 * @see <MongoBaseDao>
 */
@Repository
public class AdPatientDocumentDao extends MongoBaseDao {

    /**
     * <患者档案记录的collectionName>
     */
    private static final String COLLECTION_NAME = "m_patient_document";

    @Autowired
    private MongoTemplate mongoTemplate;

    public MPatientDocument queryDocument(Long patientId) {

        Criteria criteria = Criteria.where("patientId").is(patientId);
        // 查询
        Query query = Query.query(criteria);
        List<MPatientDocument> results = super.find(query, MPatientDocument.class, COLLECTION_NAME);
        // 返回查询结果
        return results.size() > 0 ? results.get(0) : null;
    }

    @Override
    protected MongoTemplate getMongoTemplate() {
        return mongoTemplate;
    }
}
